package com.yuexun.beilunpatient.ui.my.ui;

import android.content.Intent;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.yuexun.beilunpatient.R;
import com.yuexun.beilunpatient.base.BaseKJActivity;
import com.yuexun.beilunpatient.ui.login.bean.UserDtlBean;

import org.kymjs.kjframe.ui.ViewInject;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by chenss on 2018/8/20.
 */
public class Act_Personal_Edit extends BaseKJActivity {

    @Bind(R.id.title_tv)
    TextView titleTv;
    @Bind(R.id.theme)
    TextView theme;
    @Bind(R.id.edit_content)
    EditText editContent;
    @Bind(R.id.unit)
    TextView unit;

    UserDtlBean userDtlBean;
    String title;

    @Override
    public void setRootView() {
        super.setRootView();
        setContentView(R.layout.act_personal_edit);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        title = getIntent().getExtras().getString("title");
        userDtlBean = (UserDtlBean) getIntent().getExtras().getSerializable("userData");
        titleTv.setText(title);
        theme.setText(title);
        editContent.setHint("请输入" + title);

        if (title.equals("身高")) {
            editContent.setInputType(InputType.TYPE_CLASS_NUMBER);
            unit.setVisibility(View.VISIBLE);
            unit.setText("单位厘米（CM）");
        } else if (title.equals("体重")) {
            editContent.setInputType(InputType.TYPE_CLASS_NUMBER);
            unit.setVisibility(View.VISIBLE);
            unit.setText("单位千克（Kg）");
        } else if (title.equals("邮编")) {
            editContent.setInputType(InputType.TYPE_CLASS_NUMBER);
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.back, R.id.save})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.save:
                if (title.equals("邮箱") && !editContent.getText().toString().contains("@")) {
                    ViewInject.toast("邮箱输入有误!");
                    break;
                }
                if(title.equals("职业")){
                    userDtlBean.setProfession(editContent.getText().toString());
                }else if(title.equals("身高")){
                    userDtlBean.setHeight(editContent.getText().toString());
                }else if(title.equals("体重")){
                    userDtlBean.setWeight(editContent.getText().toString());
                }else if(title.equals("过敏史")){
                    userDtlBean.setAllergyHistory(editContent.getText().toString());
                }else if(title.equals("家庭病史")){
                    userDtlBean.setFamilyMedicalHistory(editContent.getText().toString());
                }else if(title.equals("邮箱")){
                    userDtlBean.setEmail(editContent.getText().toString());
                }else if(title.equals("家庭地址")){
                    userDtlBean.setAddress(editContent.getText().toString());
                }else if(title.equals("邮编")){
                    userDtlBean.setPostcode(editContent.getText().toString());
                }

                Bundle bundle = new Bundle();
                Intent intent = new Intent();
                bundle.putSerializable("userData", userDtlBean);
                intent.putExtras(bundle);
                setResult(0x001, intent);
                finish();
                break;
        }
    }
}
